import java.util.ArrayList;

/**
 * 约瑟夫问题
 */
public class Joseph2 {
    /**
     * TODO
     *
     * @param args 参数
     * @return void
     */
    public static void main(String[] args) {
        joseph(20, 5, 3);
    }

    /**
     * @param total 总人数
     * @param count 数到几出列
     * @param start 从谁开始
     */
    public static void joseph(int total, int count, int start) {

        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i <= total; i++) {
            list.add("" + i);
        }
        //因为数组从0开始
        int startIndex = start - 1;
        int countActual = count - 1;
        while (list.size() > 0) {

            startIndex = (startIndex + countActual) % list.size();

            System.out.println("队列:" + list);
            System.out.println("出队:" + list.get(startIndex));
            list.remove(startIndex);
        }
    }
}
